<div class="container-fluid">
    <div class="row">
        <div class="page-header">
            <h1>Listagem <small>de Mercados</small></h1>
        </div>
    </div>
    
    <div class="row">
		<div >
			<ul class="breadcrumb">
			    <li><?php echo $this->href(array('controller' => 'index', 'action' => 'index', 'module' => 'default', 'content' => 'Home', 'checkAcl' => true))?></li> <span class="text-info divider"> >> </span>
				<li><?php echo $this->href(array('controller' => 'usuario', 'action' => 'board', 'module' => 'default', 'content' => 'Meu Ambiente', 'checkAcl' => true))?></li></li> <span class="text-info divider"> >> </span>
			    <li class="active">Listar Mercados</li>
			 </ul>
		 </div>
	</div>
	
	<?php if ($this->message == Messages::MERCADO_PREFERIDO_ADD_SUCESSO):?>
	<div class="alert alert-success">
		<button type="button" class="close" data-dismiss="alert">&times;</button>
		<strong><?php echo Messages::getMessage(Messages::MERCADO_PREFERIDO_ADD_SUCESSO)?></strong>
	</div>
	<?php endif; ?>	
	
	<?php if ($this->message == Messages::MERCADO_PREFERIDO_LIMITE):?>
	<div class="alert alert-danger">
		<button type="button" class="close" data-dismiss="alert">&times;</button>
		<strong><?php echo Messages::getMessage(Messages::MERCADO_PREFERIDO_LIMITE)?></strong>
	</div>
	<?php endif; ?>
	
	<?php if ($this->message == Messages::MERCADO_PREFERIDO_REMOVE_SUCESSO):?>
	<div class="alert alert-success">
		<button type="button" class="close" data-dismiss="alert">&times;</button>
		<strong><?php echo Messages::getMessage(Messages::MERCADO_PREFERIDO_REMOVE_SUCESSO)?></strong>
	</div>
	<?php endif; ?>		
	
	<?php if ($this->message == Messages::MERCADO_JAH_EXISTE):?>
	<div class="alert alert-danger">
		<button type="button" class="close" data-dismiss="alert">&times;</button>
		<strong><?php echo Messages::getMessage(Messages::MERCADO_JAH_EXISTE)?></strong>
	</div>
	<?php endif; ?>	
	
	<?php if ($this->message == Messages::MERCADO_CRIADO):?>
	<div class="alert alert-success">
		<button type="button" class="close" data-dismiss="alert">&times;</button>
		<strong><?php echo Messages::getMessage(Messages::MERCADO_CRIADO)?></strong>
	</div>
	<?php endif; ?>	
    
    <div class="row">
        <table class="table table-striped table-responsive">
            <thead>
                <th></th>
                <th>Rede</th>
                <th>Mercado</th>
                <th></th>
            </thead>
            
            <tbody>
                <?php foreach ($this->mercados as $mercado) { ?>
                <tr>
                    <td>
                    <?php 
                        if ($mercado->ehPreferido($this->idUsuario)){
                            echo '<i class="glyphicon glyphicon-heart data-toggle="tooltip" data-placement="left" title="Mercado Preferido"></i> ';
                        }
                    ?>
                    </td>
                    <td><?php echo $mercado->getRede()->nm_rede_mercado ?>
                    </td>
                    <td>
                        <?php echo $mercado->nm_mercado ?>
                    </td>
                    <td>
                        <?php if (!$mercado->ehPreferido($this->idUsuario)){ ?>
                        <?php echo $this->href(array('controller' => 'mercado', 'action' => 'add-mercado-preferido', 'module' => 'default', 'attribs' => array('data-toggle' => 'tooltip', 'data-placement' => 'left', 'title' => 'Adicionar mercado como favorito'), 'params' => array('idMercado' => $mercado->id_mercado) ,'content' => '<i class="glyphicon glyphicon-plus"></i>', 'checkAcl' => true))?>
                        <?php }else{ ?>
                        <?php echo $this->href(array('controller' => 'mercado', 'action' => 'remove-mercado-preferido', 'module' => 'default', 'attribs' => array('data-toggle' => 'tooltip', 'data-placement' => 'left', 'title' => 'Remover mercado dos favoritos'), 'params' => array('idMercado' => $mercado->id_mercado) ,'content' => '<i class="glyphicon glyphicon-minus"></i>', 'checkAcl' => true))?>
                        <?php } ?>
                    </td>
                    <td>
						<?php echo $this->href(array('controller' => 'mercado', 'action' => 'editar', 'module' => 'default', 'attribs' => array('data-toggle' => 'tooltip', 'data-placement' => 'left', 'title' => 'Editar Mercado'), 'params' => array('id' => $mercado->id_mercado) ,'content' => '<i class="glyphicon glyphicon-edit"></i>', 'checkAcl' => true))?>
                    </td>
                    <td>
                        <?php if ($mercado->st_mercado == TipoBloqueio::BLOQUEADO):?>
                            <?php echo $this->href(array('controller' => 'mercado', 'action' => 'bloquear', 'module' => 'default', 'attribs' => array('data-toggle' => 'tooltip', 'data-placement' => 'left', 'title' => 'Desbloquear Mercado'), 'params' => array('id' => $mercado->id_mercado) ,'content' => '<i class="glyphicon glyphicon-ok"></i>', 'checkAcl' => true))?>
                        <?php else: ?>
                            <?php echo $this->href(array('controller' => 'mercado', 'action' => 'bloquear', 'module' => 'default', 'attribs' => array('data-toggle' => 'tooltip', 'data-placement' => 'left', 'title' => 'Bloquear Mercado'), 'params' => array('id' => $mercado->id_mercado) ,'content' => '<i class="glyphicon glyphicon-ban-circle"></i>', 'checkAcl' => true))?>
                        <?php endif; ?>
                    </td>                    
                </tr>
                <?php } ?>
            </tbody>
        </table>
		<p style="text-align: center;"><?php echo $this->href(array('controller' => 'mercado', 'action' => 'criar', 'module' => 'default', 'content' => '<button type="button" class="btn btn-primary btn-lg">Cadastrar novo mercado</button>', 'checkAcl' => false))?></p>                
    </div>
</div>
